package org.gourpg.entity.organization;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.proxy.HibernateProxy;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Timestamp;
import java.util.Objects;

/**
 * 组织配置实体
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "org_detail")
public class OrgDetails {
    /**
     * 组织ID，组织的主键
     */
    @Id
    private Long orgId;

    /**
     * 组织名称
     */
    private String orgName;

    /**
     * 组织上层ID，形成自关联关系
     */
    private Integer orgParentId;

    /**
     * 组织创建时间
     */
    private Timestamp orgStartTime;

    /**
     * 组织关闭时间
     */
    private Timestamp orgEndTime;

    /**
     * 组织状态 （运营中、关闭）字典 ORG_STATUS
     */
    private String orgStatus;


    protected boolean canEqual(final Object other) {
        return other instanceof OrgDetails;
    }

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        OrgDetails that = (OrgDetails) o;
        return getOrgId() != null && Objects.equals(getOrgId(), that.getOrgId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}
